import axios from "axios";
import { ElMessage } from "element-plus";
import 'element-plus/dist/index.css'


const axiox = axios.create({
    baseURL: import.meta.env.VITE_BACKEND_API_BASE_URL
})


axiox.interceptors.request.use(
    (config)=>{
        config.headers = {
            BlogToken : localStorage.getItem("BlogToken")
        }
        return config;
    },
    (error)=>{
        return Promise.reject(error)
    }
)
axiox.interceptors.response.use(
    (response)=>{
        return response;
    },
    (error)=>{
        switch(error.response?.status){
            case 400:
                ElMessage.error("页面异常")
            break
            default:
                ElMessage.error("未知异常")
        }
        return Promise.resolve({})
    }
)
export default axiox